package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import java.io.File;

@Controller
public class UploadController {

    @RequestMapping("/upload")
    public void upload(@RequestParam("picture") MultipartFile picture) throws Exception {
        //获取文件的原始名称
        System.out.println(picture.getOriginalFilename());
        //文件类型
        System.out.println("\t" + picture.getContentType());

        //目标文件
        File desFile = new File("D:\\upload\\" + picture.getOriginalFilename());
        //保持到文件
        picture.transferTo(desFile);
    }

    @RequestMapping("/test2")
    public ModelAndView upload() {
        return new ModelAndView("upload");
    }

}